using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using THANHTUNGO.Portal.Components.UI;

namespace THANHTUNGO.Portal.Modules.SECURITY
{
    public enum ModulePages
    {
        Users,
        Roles,
        Permissions
    }


    public partial class Main : PortalModuleControl
    {
        private void loadChildControl()
        {
            string m_baseDir = "~/Modules/SECURITY/";
            string pageQuery = "Page" + this.ModuleID;
            string pageName = Request.QueryString[pageQuery];

            ModulePages page;
            if (pageName == null)
            {
                page = ModulePages.Users;
            }
            else
            {
                page = (ModulePages)Enum.Parse(typeof(ModulePages), Request.QueryString[pageQuery], true);
            }

            string src = string.Format("{0}Controls/{1}.ascx", m_baseDir, page);
            if (src.IndexOf("/Mod_") >= 0)
                src = src.Replace("/Mod_", "/Mod/");
            if (src.IndexOf("/Admin_") >= 0)
                src = src.Replace("/Admin_", "/Admin/");
            if (src.IndexOf("/Help_") >= 0)
                src = src.Replace("/Help_", "/Help/");

            YAFPage ctl = (YAFPage)this.LoadControl(src);
            ctl.ParentControl = this;
            ContentPane.Controls.Add(ctl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.loadChildControl();
            if (IsPostBack == false)
            {
                hlUser.NavigateUrl = YAFUrlBuilder.GetLink(this.ModuleID, ModulePages.Users);
                hlRole.NavigateUrl = YAFUrlBuilder.GetLink(this.ModuleID, ModulePages.Roles);
            }
        }
    }
}